/**
 * Class TableSpanModule.
 * 
 * @author JLS
 * 
 */
TableSpanModule.inherits(TableModule);
function TableSpanModule(params) {
	params = Util.getObject(params);
	this.parentConstructor(TableModule, params);
}

/**
 * Fills the given jQ element
 * @param jQ
 */
TableSpanModule.prototype.fillJQ = function(jQ) {
	var that = this;

	this.fillHead(jQ);
	
	var tbody = $('<tbody></tbody>');
	jQ.append(tbody);
	var i = 0;
	var previous = {};
	this.objectMap.foreach(function(id, object) {
		var tr = $('<tr id="' + id + '" class="' + (i++ % 2 == 0 ? 'even' : that.withOddEven ? 'odd' : '') + (that.selectedObject == object ? ' selected' : '') + '"></tr>');
		that.columnList.foreach(function(index, column) {
			var jQTd = column.getJQTd(object);
			if (column.clickable) {
				jQTd.click(function() {
					Util.getFunction(that.onClickTr).call(that, $(this).parent());
				});
			}
			//rowspan it
			prev = previous[column.attr];
			if (Util.check(prev) && prev.text == column.getText(object)) {
				var rs = parseInt(prev.jq.attr('rowspan'));
				prev.jq.attr('rowspan', isNaN(rs) ? 2 : rs + 1);
			} else {
				previous[column.attr] = {'jq' : jQTd, 'text' : column.getText(object)};
				tr.append(jQTd);
			}
			//TODO colspan it (if needed)
		});
		tbody.append(tr);
	});

	if (this.pagerShow) {
		jQ.append($('<tfoot></tfoot>').append(this.getJQPagerTr()));
	}
};

